package org.canaan.http.urlpair.core;


import org.canaan.http.urlpair.resolver.UrlPairResolver;
import org.canaan.http.urlpair.resolver.impl.ArrayListResolver;
import org.canaan.http.urlpair.resolver.impl.BaseTypeResolver;
import org.canaan.http.urlpair.resolver.impl.ListResolver;

import java.util.ArrayList;
import java.util.List;

/**
 * 对象解析链,分别解析 基本类型，集合类型及数组类型
 * @author Canaan
 * @date 2017/6/29 0029
 */
 class ParseChain {

    private List<UrlPairResolver> resolvers;

    public ParseChain() {
        resolvers = new ArrayList<>();
        resolvers.add(new BaseTypeResolver());
        resolvers.add(new ListResolver());
        resolvers.add(new ArrayListResolver());
    }

    public String doParse(String key ,Object value) {
        String result = "";
        for (UrlPairResolver resolver : this.resolvers) {
            if(resolver.resolvable(value)){
                return resolver.resolve(key,value);
            }
        }
        return result;
    }
}
